import request, { requestWithConfig, requestWithResult } from '@/utils/request'
import { PageData } from '@/types/resp.ts'
import { Blog, BlogPageParam, GetParam, BlogTopListParam, BlogVisitSaveParam } from '@/types/api.ts'

//博客列表接口
export const page = (param: BlogPageParam): Promise<PageData<Blog>> => {
  return request({
    url: '/portal/blog/page',
    method: 'post',
    data: param,
  })
}
//获取博客详情
export const get = (param: GetParam): Promise<Blog> => {
  return request({
    url: '/portal/blog/get',
    method: 'post',
    data: param,
  })
}

//精选博客接口
export const topList = (param: BlogTopListParam): Promise<Blog[]> => {
  return request({
    url: '/portal/blog/top/list',
    method: 'post',
    data: param,
  })
}

// 博客查看、点赞记录接口，返回code码为816时，表示已经点赞或查看过
export const saveBlogVisit = (param: BlogVisitSaveParam): Promise<unknown> => {
  return requestWithConfig({
    url: '/portal/blog/visit/save',
    method: 'post',
    data: param,
    ignoreErrorCodes: [816], // 忽略816状态码（已经点赞或查看过）
  })
}

// 博客查看、点赞记录接口，返回完整结果信息（包含状态码）
export const saveBlogVisitWithResult = (param: BlogVisitSaveParam) => {
  return requestWithResult({
    url: '/portal/blog/visit/save',
    method: 'post',
    data: param,
  })
}
